package vv.lines.view.swing;

import vv.lines.core.IActionHandler;
import vv.lines.core.animations.Animation;
import vv.lines.view.*;
import vv.lines.view.swing.animation.SwingActiveAnimation;
import vv.lines.view.swing.animation.SwingAlphaAnimation;
import vv.lines.view.swing.animation.SwingMoveAnimation;
import vv.lines.view.swing.utils.SwingResourceHolder;

import javax.swing.*;

import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog;

/**
 *
 * @author vpotapenko
 */
public class SwingViewFactory extends ViewFactory {

    private SwingResourceHolder resourceHolder;

    public SwingViewFactory(int maxValue) {
        resourceHolder = new SwingResourceHolder(maxValue);
    }

    @Override
    protected WindowView newWindowView(IActionHandler handler) {
        return new SwingWindowView(handler, resourceHolder);
    }

    @Override
    protected FieldView newFieldView() {
        return new SwingFieldView();
    }

    @Override
    protected CellView newCellView() {
        return new SwingCellView();
    }

    @Override
    protected BallView newBallView() {
        return new SwingBallView(resourceHolder);
    }

    @Override
    protected ViewTimer newViewTimer() {
        return new SwingViewTimer();
    }

    @Override
    protected Animation newMoveAnimation() {
        return new SwingMoveAnimation();
    }

    @Override
    protected Animation newActiveAnimation() {
        return new SwingActiveAnimation();
    }

    @Override
    protected Animation newShowAnimation() {
        return new SwingAlphaAnimation(true);
    }

    @Override
    protected Animation newHideAnimation() {
        return new SwingAlphaAnimation(false);
    }

    @Override
    public void showMessageBox(String title, String text) {
        showMessageDialog(null, text, title, INFORMATION_MESSAGE);
    }

    @Override
    public String showInputBox(String message, String initialValue) {
        return JOptionPane.showInputDialog(null, message, "jColorLines",
                INFORMATION_MESSAGE);
    }

    @Override
    protected TextDialogView newTextWindowView() {
        return new SwingTextDialogView(resourceHolder);
    }
}
